package com.virus.mall.utils;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

/**
 * @Classname MybatisUtils
 * @Description NULL
 * @Date 2021/4/13 14:34
 * @Created by virus
 */
public class MybatisUtils {

    private static final String resource = "mybatis-config.xml";

    public static SqlSession getSession() {
        InputStream inputStream = MybatisUtils.class.getClassLoader().getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        return sqlSessionFactory.openSession();
    }

    public static void releaseSession(SqlSession sqlSession) {
        sqlSession.commit();
        sqlSession.close();
    }
}
